package com.bkq.viettravel;

import com.bkq.viettravel.LoaderImageView;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import android.app.Activity;
import android.app.ListActivity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class Plan extends ListActivity {
	private LayoutInflater mInflater;
	private Vector<RowData> data;
	RowData rd;
	
	static final String[] name = new String[] {"Ba Na ......","Chua linh ung .....","Furama Resort ....","Bai but ..........."};
	static final String[] info = new String[] {"Rat dep","Rat dep","Rat dep","Rat dep","Rat dep"};
	static final String[] timeBegin = new String[] {"1h","13h","4h","3h","6h"};
	static final String[] timeEnd = new String[] {"1h","13h","4h","3h","6h"};
	static final String[] numberPeople = new String[] {"12","13","4","3","6"};

	static final String[] note = new String[] {"","","","",""};
	
	static Button bntBack, bntHome, bntFavorite, bntAbout, bntPlan, bntEditPlan, bntRemovePlan;
	
	
	@Override
	public void onCreate(Bundle savedInstanceState)  {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.plan);
		mInflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
		data = new Vector<RowData>();
	
		for(int i=0;i<name.length;i++){
			rd = new RowData(i,name[i],info[i],timeBegin[i],timeEnd[i],numberPeople[i],note[i]);
			data.add(rd);
		}
	
	   CustomAdapter adapter = new CustomAdapter(this, R.layout.plan_row,R.id.plan_Bnt_info, data);
	   setListAdapter(adapter);
	   getListView().setTextFilterEnabled(true);
	   
	   bntBack = (Button) findViewById(R.id.plan_Bnt_back);
	   bntHome = (Button) findViewById(R.id.plan_Bnt_home);
	   bntFavorite = (Button) findViewById(R.id.plan_Bnt_favourite);
	   bntAbout = (Button) findViewById(R.id.plan_Bnt_info);
	   bntPlan = (Button) findViewById(R.id.plan_Bnt_plan);
	   bntEditPlan = (Button) findViewById(R.id.plan_Bnt_edit_plan);
	   bntRemovePlan = (Button) findViewById(R.id.plan_Bnt_removePlan);
	   
	   bntHome.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			bntHome.setBackgroundDrawable(getApplicationContext().getResources().getDrawable(R.drawable.icon_trangchinh_selected));
			bntPlan.setBackgroundDrawable(getApplicationContext().getResources().getDrawable(R.drawable.icon_kehoach));
			Intent i = new Intent(Plan.this,VietTravelActivity.class);
			startActivity(i);
		}
	   });
	   
	   bntFavorite.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			bntFavorite.setBackgroundDrawable(getApplicationContext().getResources().getDrawable(R.drawable.icon_uuthich_selected));
			bntPlan.setBackgroundDrawable(getApplicationContext().getResources().getDrawable(R.drawable.icon_kehoach));
			Intent i = new Intent(Plan.this,FavoritesActivity.class);
			startActivity(i);
		}
	   });
	   
	   bntAbout.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			bntAbout.setBackgroundDrawable(getApplicationContext().getResources().getDrawable(R.drawable.icon_thongtin_selected));
			bntPlan.setBackgroundDrawable(getApplicationContext().getResources().getDrawable(R.drawable.icon_kehoach));
			Intent i = new Intent(getBaseContext(),About.class);
			startActivity(i);
		}
	   });
	   
	   bntBack.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			bntBack.setBackgroundDrawable(getApplicationContext().getResources().getDrawable(R.drawable.icon_back_selected));
			bntPlan.setBackgroundDrawable(getApplicationContext().getResources().getDrawable(R.drawable.icon_kehoach));
			Intent i = new Intent(getBaseContext(),InformationTravelActivity.class);
			startActivity(i);
		}
	   });
	   
	   
	   
	}
	
	private class RowData {
		protected int mId;
		protected String mName;
	    protected String mInfo;
	    protected String mTimeBegin;
	    protected String mTimeEnd;
	    protected String mNumberPeople;
	    protected String mNote;
	    RowData(int id, String name,String info,String timeBegin, String timeEnd, String numberPeople, String note){
	    mId=id;
	    mName =name;
	    mInfo = info;
	    mTimeBegin=timeBegin;
	    mTimeEnd=timeEnd;
	    mNumberPeople=numberPeople;
	    mNote=note;
	    }
	       @Override
	    public String toString() {
	    	   return mId+" "+mName+" "+mInfo+" "+mTimeBegin+" "+mTimeEnd+" "+mNumberPeople+" "+mNote;
	       }
	}
	  private class CustomAdapter extends ArrayAdapter<RowData> {
	 
		  public CustomAdapter(Context context, int resource,int textViewResourceId, List<RowData> objects) {               
			  super(context, resource, textViewResourceId, objects);
		  }
	      @Override
	      public View getView(int position, View convertView, ViewGroup parent) {   
	    	  ViewHolder holder = null;
	    	  TextView name = null;
	    	  TextView info = null;
	    	  TextView timeBegin = null;
	    	  TextView timeEnd = null;
	    	  TextView numberPeople = null;
	    	  TextView note = null;
	    	  Button editPlanBtn;
	    	  Button removePlanBtn;
	    	  LoaderImageView image_plan=null;
	    	  RowData rowData= getItem(position);
	    	  if(null == convertView){
	    		  convertView = mInflater.inflate(R.layout.plan_row, null);
	    		  holder = new ViewHolder(convertView);
	    		  convertView.setTag(holder);
	    	  }
	          holder = (ViewHolder) convertView.getTag();
	          name = holder.getname();
	          name.setText(rowData.mName);
	          info = holder.getinfo();
	          info.setText(rowData.mInfo);
	          timeBegin = holder.gettimeBegin();
	          timeBegin.setText(rowData.mTimeBegin);    
	          timeEnd = holder.gettimeEnd();
	          timeEnd.setText(rowData.mTimeEnd);  
	          numberPeople = holder.getnumberPeople();
	          numberPeople.setText(rowData.mNumberPeople);
	          note = holder.getnote();
	          note.setText(rowData.mNote);
	          image_plan=holder.getImage();
	          editPlanBtn = holder.getEditBtn();
	          
	          
	          if(editPlanBtn != null)
	          {
	        	  editPlanBtn.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						
						
					}
				});
	          }
	          removePlanBtn = holder.getRemoveBnt();
	          if(removePlanBtn != null)
	          {
	        	  removePlanBtn.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						
						
					}
				});
	          }
	         
	          return convertView;
	      }
	      private class ViewHolder {
	    	  private View mRow;
	    	  private TextView name = null;
	          private TextView info = null;
	          private TextView timeBegin = null;
	          private TextView timeEnd = null;
	          private TextView numberPeople = null;
	          private TextView note = null;
	          private Button bntEditPlan, bntRemovePlan;
	          
	          public LoaderImageView image_plan = null;
	          
	          public ViewHolder(View row) {
	        	  mRow = row;
	          }
	          
	          public Button getEditBtn()
	          {
	        	  if(null == bntEditPlan)
	        	  {
	        		  bntEditPlan = (Button) mRow.findViewById(R.id.plan_Bnt_edit_plan);
	        	  }
	        	  return bntEditPlan;
	          }
	          
	          
	          public Button getRemoveBnt()
	          {
	        	  if(null == bntRemovePlan)
	        	  {
	        		  bntRemovePlan = (Button) mRow.findViewById(R.id.plan_Bnt_removePlan);
	        	  }
	        	  return Plan.bntRemovePlan;
	          }
	          
	          
	          public TextView getname() {
	        	   if(null == name){
	        		   name = (TextView) mRow.findViewById(R.id.plan_Tv_name);
	               }
	        	   return name;
	         }   
	          
	         public TextView getinfo() {
	        	   if(null == info){
	        		   info = (TextView) mRow.findViewById(R.id.plan_Tv_info);
	               }
	        	   return info;
	         }   
	          
	         public TextView gettimeBegin() {
	             if(null == timeBegin){
	            	 timeBegin = (TextView) mRow.findViewById(R.id.plan_Tv_begin);
	             }
	             return timeBegin;
	         }
	         
	         public TextView gettimeEnd() {
	             if(null == timeEnd){
	            	 timeEnd = (TextView) mRow.findViewById(R.id.plan_Tv_end);
	             }
	             return timeEnd;
	         }
	         
	         public TextView getnumberPeople() {
	        	   if(null == numberPeople){
	        		   numberPeople = (TextView) mRow.findViewById(R.id.plan_Tv_numberPeople);
	               }
	        	   return numberPeople;
	         }    
	         
	         public TextView getnote() {
	        	   if(null == note){
	        		   note = (TextView) mRow.findViewById(R.id.plan_Tv_note);
	               }
	        	   return note;
	         }   
	         
	         public LoaderImageView getImage() {
	             if(null == image_plan){
	                  image_plan = (LoaderImageView) mRow.findViewById(R.id.plan_Ima);
	             }
	             return image_plan;
	        }
	     }
	} 
}
